package com.cqw.auth.controller;

import com.cqw.auth.entry.User;
import com.cqw.auth.service.UserService;
import com.power.common.model.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * User Information Operation Interface
 * @author 11700 on 2020/12/30.
 */
@RestController
@RequestMapping("user")
public class UserController {

	@Resource
	private UserService userService;

    /**
	 * Add user info
	 * @param entity user info
	 * @return
	 */
	@PostMapping(value = "/add")
	public CommonResult save(@RequestBody User entity) {
	    userService.save(entity);
		return CommonResult.ok();
	}

    /**
	 * Update user info
	 * @param entity user info
	 * @return
	 */
	@PostMapping(value = "/update")
	public CommonResult update(@RequestBody User entity) {
	    userService.updateById(entity);
		return CommonResult.ok();
	}

    /**
	 * Delete user by id
	 * @param id user id
	 * @return
	 */
	@GetMapping(value = "/delete/{id}")
	public CommonResult delete(@PathVariable Integer id) {
	    userService.removeById(id);
		return CommonResult.ok();
	}

    /**
	 * Query user by id
	 * @param id user id
	 * @return
	 */
	@GetMapping(value = "/query/{id}")
	public CommonResult<User> queryById(@PathVariable Integer id) {
	    User entity = userService.getById(id);
		return CommonResult.ok().setResult(entity);
	}

}